package FileIO.stream;

import FileIO.Student;

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class useDataInputStream {
    public static void main(String[] args) throws IOException {
        DataInputStream input = new DataInputStream(new FileInputStream("src/main/data/students.dat"));
        try {
            int size = input.readInt();
            List<Student> studentList = new ArrayList<>();
            for (int i = 0; i < size; i++) {
                Student s = new Student();
                s.setName(input.readUTF());
                s.setAge(input.readInt());
                s.setScore(input.readDouble());
                studentList.add(s);
            }
            for (int i = 0; i < size; i++) {
                System.out.println(studentList.get(i));
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            input.close();
        }
    }
}
